<script src="js/jquery.js"></script>
<script src="js/jquery.validate.js"></script>

<script>
$.validator.setDefaults({
	submitHandler: function() { alert("submitted!"); }
});

$().ready(function() {
	// validate the comment form when it is submitted
	$("#commentForm").validate();

	$("#changePass").validate({
		rules: {
			oldpass: "required",
			newpass: {
				required: true,
				minlength: 5
			},
			repeatpass: {
				required: true,
				minlength: 5,
				equalTo: "#newpass"
			},
		},
		messages: {
			oldpass: "请输入当前密码",
			newpass: {
				required: "Please enter a username",
				minlength: "Your username must consist of at least 2 characters"
			},
			repeatpass: {
				required: "Please provide a password",
				minlength: "Your password must be at least 5 characters long",
				equalTo: "Please enter the same password as above"
			},
		}
	});

	// validate signup form on keyup and submit
	$("#signupForm").validate({
		rules: {
			firstname: "required",
			lastname: "required",
			username: {
				required: true,
				minlength: 2
			},
			password: {
				required: true,
				minlength: 5
			},
			confirm_password: {
				required: true,
				minlength: 5,
				equalTo: "#password"
			},
			email: {
				required: true,
				email: true
			},
			topic: {
				required: "#newsletter:checked",
				minlength: 2
			},
			agree: "required"
		},
		messages: {
			firstname: "Please enter your firstname",
			lastname: "Please enter your lastname",
			username: {
				required: "Please enter a username",
				minlength: "Your username must consist of at least 2 characters"
			},
			password: {
				required: "Please provide a password",
				minlength: "Your password must be at least 5 characters long"
			},
			confirm_password: {
				required: "Please provide a password",
				minlength: "Your password must be at least 5 characters long",
				equalTo: "Please enter the same password as above"
			},
			email: "Please enter a valid email address",
			agree: "Please accept our policy"
		}
	});

});
</script>


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery validation plug-in - main demo</title>

</head>
<body>

<form  id="signupForm" >
	<fieldset>
		<legend>Validating a complete form</legend>
		<p>
			<label for="firstname">Firstname</label>
			<input id="firstname" name="firstname" type="text" />
		</p>
		<p>
			<label for="lastname">Lastname</label>
			<input id="lastname" name="lastname" type="text" />
		</p>
		<p>
			<label for="username">Username</label>
			<input id="username" name="username" type="text" />
		</p>
		<p>
			<label for="password">Password</label>
			<input id="password" name="password" type="password" />
		</p>
		<p>
			<label for="confirm_password">Confirm password</label>
			<input id="confirm_password" name="confirm_password" type="password" />
		</p>
		<p>
			<label for="email">Email</label>
			<input id="email" name="email" type="email" />
		</p>
		<p>
			<label for="agree">Please agree to our policy</label>
			<input type="checkbox" class="checkbox" id="agree" name="agree" />
		</p>
		<p>
			<label for="newsletter">I'd like to receive the newsletter</label>
			<input type="checkbox" class="checkbox" id="newsletter" name="newsletter" />
		</p>
		<fieldset id="newsletter_topics">
			<legend>Topics (select at least two) - note: would be hidden when newsletter isn't selected, but is visible here for the demo</legend>
			<label for="topic_marketflash">
				<input type="checkbox" id="topic_marketflash" value="marketflash" name="topic" />
				Marketflash
			</label>
			<label for="topic_fuzz">
				<input type="checkbox" id="topic_fuzz" value="fuzz" name="topic" />
				Latest fuzz
			</label>
			<label for="topic_digester">
				<input type="checkbox" id="topic_digester" value="digester" name="topic" />
				Mailing list digester
			</label>
			<label for="topic" class="error">Please select at least two topics you'd like to receive.</label>
		</fieldset>
		<p>
			<input class="submit" type="submit" value="Submit"/>
		</p>
	</fieldset>
</form>

						<form id="changePass" class="form-horizontal">
							<fieldset>
							  <div class="control-group">
								<label class="control-label" for="ocusedInput">当前密码</label>
								<div class="controls">
								  <input class="input-large focused" id="oldpass" name="oldpass" type="password" value="">
								</div>
							  </div>
							  <div class="control-group">
								<label class="control-label">新密码</label>
								<div class="controls">
								  <input class="input-large" id="newpass" name="newpass" type="password" value="">
								</div>
							  </div>
                              <div class="control-group">
								<label class="control-label">确认密码</label>
								<div class="controls">
								  <input class="input-large" id="repeatpass" name="repeatpass" type="password" value="">
								</div>
							  </div>
							  <div class="form-actions">
								<button type="submit" class="btn btn-primary">保存密码</button>
								<button class="btn">取消修改</button>
							  </div>
							</fieldset>
						  </form>
</body>
</html>
